home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / examples / section9 / ex9_7.C < prev    next >
C/C++ Source or Header  |  1992-05-16  |  2KB  |  46 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/AVL_Tree.h>            // Include AVL tree class
  14. #include <cool/String.h>            // Include COOL String class
  15. #include <cool/Gen_String.h>            // Include COOL Gen_String class
  16.  
  17. #include <cool/Binary_Node.C>
  18. #include <cool/Binary_Tree.C>
  19. #include <cool/AVL_Tree.C>
  20.  
  21. static CoolGen_String text ("\n\
  22.      A programming language serves two related purposes: it provides a\n\
  23.      vehicle for the programmer to specify actions to be executed and a\n\
  24.      set of concepts for the programmer to use when thinking about what\n\
  25.      can be done.");
  26.  
  27. DECLARE CoolAVL_Tree<CoolString>        // Declare tree type
  28. IMPLEMENT CoolAVL_Tree<CoolString>        // Implement tree type
  29. IMPLEMENT CoolBinary_Tree<CoolString>
  30. IMPLEMENT CoolBinary_Node<CoolString>
  31.  
  32. int main (void) {
  33.   CoolAVL_Tree<CoolString> avl1;        // Declare tree variable
  34.   CoolGen_String s;                // Temporary CoolString variable
  35.   text.compile ("[a-zA-Z]+");            // Match any alphabetical word
  36.   while (text.find ()) {            // While still more words
  37.     text.sub_string (s, text.start (), text.end ()); // Get word from paragraph
  38.     avl1.put (*(new CoolString(upcase (s))));         // And add to tree
  39.   }
  40.   //Bug here, AVL Tree is not completely balanced.
  41.   //it needs one extra balance call to match structure in manual.
  42.   //avl1.balance ();
  43.   cout << avl1;                    // Output tree structure
  44.   return (0);                    // Exit with successful status
  45. }
  46.